﻿@{ ViewData["Title"] = "Index";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml"; }
@section head{
    <script type="text/javascript">
        var renderTable;
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form', 'dropdown'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table
                , dropdown = layui.dropdown;
            renderTable = function () {
                table.render({
                    elem: '#table-datalist'
                    , url: '/Console/Codetypes/GetListJson'
                    , toolbar: '#table-datalist-toolbar'
                    , limit: 20
                    , title: '类型数据表'
                    , cols: [[
                        { field: 'index', title: '序号', type: 'numbers', width: 60, templet: '#zizeng' }
                        , { field: 'codeType', title: '类型名称' }
                        , { field: 'typeCode', title: '码表代码' }
                        , { field: 'remark', title: '备注' }
                        , { field: 'creator', title: '创建人', width: 150 }
                        , { field: 'createDate', title: '添加时间', width: 160 }
                        , { field: 'operate', fixed: 'right', title: '操作', width: 150, toolbar: '#table-datalist-bar' }
                    ]]
                    , page: { layout: ['prev', 'page', 'next', 'refresh'] }
                    , done: function (res) {
                        if (res.count == 0) {
                            $(".layui-table-main").html('<div class="layui-none">' + top.lang.noData + '</div>');
                        }
                        layer.closeAll('loading');
                        /**多语言初始化 */
                        top.SetListPageLanguage(layui);
                    }
                });
            };
            renderTable();
            //头工具栏事件
            table.on('toolbar(table-datalist)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data;
                switch (obj.event) {
                    case 'addNew':
                        top.OpenPageByKey(layui, "addNew", 2, '800px', '480px', '/Console/Codetypes/Create');
                        break;
                };
            });

            //监听行工具事件
            table.on('tool(table-datalist)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') {
                    top.OpenPageByKey(layui, "edit", 2, '800px', '480px', '/Console/Codetypes/Edit?id=' + data.id);
                } else if (obj.event === 'more') {
                    //下拉菜单
                    dropdown.render({
                        elem: this //触发事件的 DOM 对象
                        , show: true //外部事件触发即显示
                        , data: [{
                            title: top.lang.lower
                            , id: 'lower'
                        }, {
                            title: top.lang.del
                            , id: 'del'
                        }]
                        , click: function (menudata) {
                            if (menudata.id === 'lower') {
                                window.location.href = "/Console/Codes/Index?type=" + data.typeCode;
                            } else if (menudata.id === 'del') {
                                var postData = {
                                    id: data.id
                                };
                                top.ConfirmByKey(layui, 'confirmDelete', postData, "/Console/Codetypes/Delete", "POST", "deleteSuccess", "deleteFail", function () {
                                    renderTable();
                                });
                            }
                        }
                        , align: 'right' //右对齐弹出（v2.6.8 新增）
                        , style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' //设置额外样式
                    })
                }
            });

        });
    </script>
}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-hide" id="table-datalist" lay-filter="table-datalist"></table>
                    <script type="text/html" id="zizeng">
                        {{d.LAY_TABLE_INDEX+1}}
                    </script>
                    <script type="text/html" id="table-datalist-toolbar">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm" lay-event="addNew">新增</button>
                        </div>
                    </script>
                    <script type="text/html" id="table-datalist-bar">
                        <button class="layui-btn layui-btn-primary layui-btn-sm" lay-event="edit">编辑</button>
                        <button class="layui-btn layui-btn-sm" lay-event="more">更多</button>
                        @*<button class="layui-btn layui-btn-sm" lay-event="edit">编辑</button>
                            <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="lower">下级管理</button>
                            <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</button>*@
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>